Skip to content
This repository has been archived by the owner on Aug 16, 2024. It is now read-only.

fix: use correct rollback tails for empty frames without history #158

Closed
wants to merge 9 commits into from

Conversation

0xVolosnikov
Copy link
Contributor

@0xVolosnikov 0xVolosnikov commented Jun 3, 2024

What ❔

At the moment, witness generation for empty frames that do not have any previous history of interactions with the state is implemented incorrectly. In such a situation, the wrong log may be selected as the corresponding tail of the rollback queue. The problem is exotic and occurs only in artificial tests.

Why ❔

Checklist

  • PR title corresponds to the body of PR (we generate changelog entries from PRs).
  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • Code has been formatted via zk fmt and zk lint.

@0xVolosnikov 0xVolosnikov requested a review from mm-zk June 3, 2024 15:36
@@ -552,8 +552,35 @@ pub fn create_artifacts_from_tracer<
// wherever we have this marker we should look at the tail of the item right before it
let pos = log_position_mapping[&rollback_tail_marker];
let tail = if pos == -1 {
// empty
global_end_of_storage_log
if frame_index > 1 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI - this is more than 'adding tests' - please update the PR description

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mm-zk you are right. Even more, proposed changes do not fix corresponding issue. I will rewrite this part of logic

// instead we should use previous frame's data
let pos_previous_frame_forward_tail = log_position_mapping
[&ExtendedLogQuery::FrameForwardTailMarker(frame_index - 1)];
if pos_previous_frame_forward_tail != -1 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add more explanations, as I couldn't fully understand the code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea: since we do not have rollback tail marker, we should try to use forward tail of the parent of this frame.

Incorrect assumption: if parent is empty too, than it is "root" frame.
Actually this is wrong. We can have any hierarchy of empty frames

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the code and added more comments

src/witness/oracle.rs Outdated Show resolved Hide resolved

if pos_forward_head == -1 && pos_forward_tail == -1 && pos_rollback_head == -1 {
// absolutely empty frame, most likely leaf one,
// but we can not just use global end,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we cannot use global end?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because we can have some state changes after this rollback. But our rollback tail should be equal to the last state change tail before the rollback.

Global end was used under assumption that situation without rollback marker can happen only in trivial cases (like entry bytecode without any state changes)

if frame_index > 1 {
// empty frame
let pos_forward_head =
log_position_mapping[&ExtendedLogQuery::FrameForwardHeadMarker(frame_index)];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need similar code in zksync-era's oracle?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need similar code in zksync-era's oracle?

I'm not sure that I understand your question: zksync-era calls this code via external_calls.rs

@0xVolosnikov
Copy link
Contributor Author

Added some todos. I'll deal with them in the next pull requests

@0xVolosnikov 0xVolosnikov requested review from mm-zk and shamatar June 14, 2024 13:12
@0xVolosnikov 0xVolosnikov changed the title feat: add test for storage access after panic fix: use correct rollback tails for empty frames without history Jun 14, 2024
@0xVolosnikov
Copy link
Contributor Author

Fixed in #165

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants